Skip to content

Let the C and Rust clients copy and parse the native payload - #21

Merged
dallison merged 3 commits into
mainfrom
rust-native-payload
Nov 5, 2026
Merged

dallison merged 3 commits into
mainfrom
rust-native-payload

Conversation

@dallison

@dallison dallison commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Summary

The C and Rust clients can now copy and parse the native Phaser payload, the
buffer itself, without going through protobuf wire format.

  • Generated C messages get <prefix>_native_payload(msg), which copies
    Data() / ByteSizeLong() into a PhaserBytes.
  • Generated C messages get <prefix>_parse_native_payload(msg, data, len).
    It returns 0 and leaves the message unchanged when the bytes are not a
    structurally valid Phaser payload. Otherwise it clears the message, takes a
    readonly view of the bytes, and CloneFroms the view into the owned message.
  • The Rust wrappers expose native_payload() -> Vec<u8> and
    parse_native_payload(&[u8]) -> bool.
  • serialize_as_string / parse_from_string are unchanged. They remain the
    protobuf transcoding.

Notes

  • Two messages with the same field values are not byte-identical. Offsets are
    absolute, and the free-list layout depends on how the message was built. Receivers
    must parse fields, not compare bytes.
  • A parsed message owns its memory. The source byte buffer does not need to
    outlive it. A movable dynamic buffer's process-local resizer pointer is
    copied but never dereferenced on the readonly parse or CloneFrom path,
    so the bytes are safe to send to another process.

Tests

  • bazelisk test //phaser/testdata:phaser_rust_test //phaser/testdata:phaser_c_api_test
    • Round-trips the native payload, including a detached copy whose source
      message is dropped before parsing.
    • Checks that protobuf bytes are rejected by parse_native_payload and leave
      the message unchanged.

Docs

  • README.md and phaser/docs/phaser_user_guide.md describe the new methods
    and that serialize_as_string stays protobuf.

serialize_as_string stays the protobuf transcoding. native_payload is the
Phaser buffer itself, so a receiver can load the fields without that step.
@dallison
dallison merged commit 4b3a80c into main Nov 5, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant